home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_327 / softfont / requester.c < prev   
C/C++ Source or Header  |  1992-05-06  |  9KB  |  317 lines

  1. /*****
  2.     requester.c
  3.  
  4.     Tom Lynch 21208 Nashville, Chatsworth, CA 91311, (818)709-2988
  5.  
  6.     This code utilizes MicroSmiths file name requester module
  7.     getfile.o
  8.  
  9.     getfile(Window,Hailing_string,file_name,directory_name);
  10.  
  11. Where:
  12.     Window is a pointer to your window
  13.     Hailing_string is a prompt displayed in the requester
  14.     file_name is a text array which will be altered by getfile,
  15.         it returns the file name.
  16.     directory_name is a text array altered by getfile, it
  17.         is the directory.
  18.  
  19.     The return value is either a pointer to your buffer, file_name,
  20.     or NULL if the user selected CANCEL.
  21.  
  22. *****/
  23.  
  24. #include <exec/types.h>
  25. #include <exec/devices.h>
  26. #include <intuition/intuition.h>
  27. #include <string.h>
  28.  
  29. extern convert();
  30. struct IntuitionBase *IntuitionBase;    /* Handles for inutition and    */
  31. struct GfxBase    *GfxBase;        /* graphics libraries        */
  32.  
  33. #define ONE 1
  34.  
  35. TEXT file_name[34];
  36. TEXT dir_name[67];
  37. TEXT portrait[67];
  38. TEXT landscape[67];
  39. TEXT slash[10] = "/";
  40. int  SLASH = '\057'; /* decimal 42, forward slash (UNIX, AMIGA) */
  41.  
  42. char *LAND  = ".land";
  43. char *temp;
  44.  
  45. struct Window    *p_Window;        /* Handle for window we open  */
  46.  
  47. /* Struct to open Window   */
  48. struct NewWindow NewWindow = {
  49.    10,10,400,150, 2,1,        /* Left,Top, Width,Height, Pens  */
  50.    MOUSEBUTTONS | MOUSEMOVE | MENUPICK | CLOSEWINDOW, /* IDCMP flags */
  51.    SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWCLOSE |
  52.    WINDOWDRAG | WINDOWDEPTH | REPORTMOUSE,    /* Window flags    */
  53.    NULL, NULL,            /* First Gadget, Checkmark image */
  54.    (UBYTE *)"Portrait-to-Landscape", /* Window Title    */
  55.    NULL, NULL,            /* Screen and BitMap        */
  56.    100,60, 32767,32767,        /* Window Sizing limits        */
  57.    WBENCHSCREEN};        /* WBENCH or CUSTOMSCREEN    */
  58.  
  59. /* Menu description  */
  60. struct IntuiText menu_text = { 2,1,JAM2, 20,1, NULL, (UBYTE *)"Start",NULL };
  61.  
  62. struct MenuItem menu_item = {
  63.    NULL, 0,10,100,10,        /* Next item, Left, Top, Width, Height */
  64.    HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
  65.    NULL,(APTR)&menu_text,    /* MutualExclude, ItemFill        */
  66.    NULL, 'S', NULL };        /* SelectFill, Command , SubItem    */
  67.  
  68. struct Menu simple_menu = {
  69.    NULL, 0,0,60,10, MENUENABLED, "Menu", &menu_item };
  70.  
  71. struct IntuiText SeventhText =
  72.     {
  73.     1,0,                /* FrontPen, BackPen */
  74.     JAM2,                /* DrawMode         */
  75.     15,90,                /* LeftEdge, TopEdge */
  76.     NULL,                /* Font (std ROM font) */
  77.     (UBYTE *)"Tom Lynch (818)709-2988",
  78.     NULL                /* NextText         */
  79. };
  80.  
  81. struct IntuiText SixthText =
  82.     {
  83.     1,0,                /* FrontPen, BackPen */
  84.     JAM2,                /* DrawMode         */
  85.     15,75,                /* LeftEdge, TopEdge */
  86.     NULL,                /* Font (std ROM font) */
  87.     (UBYTE *)"         100 filenames or system will crash.",
  88.     &SeventhText                /* NextText         */
  89. };
  90.  
  91. struct IntuiText FifthText =
  92.     {
  93.     1,0,                /* FrontPen, BackPen */
  94.     JAM2,                /* DrawMode         */
  95.     15,65,                /* LeftEdge, TopEdge */
  96.     NULL,                /* Font (std ROM font) */
  97.     (UBYTE *)"WARNING: Font directory should have less than",
  98.     &SixthText                /* NextText         */
  99. };
  100.  
  101. struct IntuiText FourthText =
  102.     {
  103.     1,0,                /* FrontPen, BackPen */
  104.     JAM2,                /* DrawMode         */
  105.     15,20,                /* LeftEdge, TopEdge */
  106.     NULL,                /* Font (std ROM font) */
  107.     (UBYTE *)"    This program will convert soft fonts",
  108.     &FifthText                /* NextText         */
  109. };
  110.  
  111. struct IntuiText ThirdText =
  112.     {
  113.     1,0,                /* FrontPen, BackPen */
  114.     JAM2,                /* DrawMode         */
  115.     15,30,                /* LeftEdge, TopEdge */
  116.     NULL,                /* Font (std ROM font) */
  117.     (UBYTE *)"for the HP LaserJet compatibles from Portrait",
  118.     &FourthText                /* NextText         */
  119. };
  120.  
  121. struct IntuiText SecondText =
  122.     {
  123.     1,0,                /* FrontPen, BackPen */
  124.     JAM2,                /* DrawMode         */
  125.     15,40,                /* LeftEdge, TopEdge */
  126.     NULL,                /* Font (std ROM font) */
  127.     (UBYTE *)"to Landscape. Repeat for each font you wish ",
  128.     &ThirdText                /* NextText         */
  129. };
  130.  
  131. struct IntuiText FirstText =
  132.     {
  133.     1,0,                /* FrontPen, BackPen */
  134.     JAM2,                /* DrawMode         */
  135.     15,50,                /* LeftEdge, TopEdge */
  136.     NULL,                /* Font (std ROM font) */
  137.     (UBYTE *)"to convert. Rename each font as desired.",
  138.     &SecondText                /* NextText         */
  139. };
  140.  
  141. /****************************************************************/
  142. /* init_window()                        */
  143. /*    Opens Window, sets up menu strip and I/O Port        */
  144. /****************************************************************/
  145. init_window()
  146. {
  147.  
  148. struct RastPort *p_WindowRastPort;
  149.  
  150. if ( ! (IntuitionBase = (struct IntuitionBase *)
  151.     OpenLibrary("intuition.library",29)) ||
  152.      ! (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",29)) )
  153.          return(2);
  154.  
  155. /* Open the window, sets handle p_Window   */
  156. if ( ! (p_Window = (struct Window *)OpenWindow( &NewWindow )) ) {
  157.     CloseLibrary(GfxBase);    CloseLibrary(IntuitionBase);
  158.     return(3);
  159.     }
  160.  
  161.     SetMenuStrip( p_Window, &simple_menu );
  162.  
  163.     p_WindowRastPort = p_Window->RPort; /* set up text window */
  164.  
  165.     PrintIText(p_WindowRastPort, &FirstText, 10L, 20L); /* write it! */
  166.  
  167.     return NULL;
  168. }
  169.  
  170. /***************************************************************/
  171. /* clear_window                                                */
  172. /*     Clears window and screen set up by init_window          */
  173. /***************************************************************/
  174. clear_window()
  175. {
  176.    ClearMenuStrip(p_Window);
  177.    CloseWindow(p_Window);
  178.     return NULL;
  179. }
  180. delay()        /* delay for 2 seconds to read error codes */
  181.     {
  182.     long t;
  183.     long tptr;
  184.     
  185.     t = time(&tptr);
  186.     while((t + 2) > time(&tptr));
  187.     return NULL;
  188. }
  189.  
  190. /*** Main:  Open window, process inputs , close window ***/
  191. void main(argc, argv)
  192. int argc;
  193. char *argv[];
  194. {
  195.             
  196. struct IntuiMessage *message;    /* Gets input event    */
  197. int    class,code;        /* Event information    */
  198. BOOL    quit_flag;        /* Application flags    */
  199. extern int n;
  200. int    error;
  201.  
  202. if (argc > 1)
  203.     {
  204.     if (argc == 3)
  205.         {
  206.         if (error = convert(argv[1],argv[2]) != 0) { /*  process the request */
  207.             printf("Failure to process font\n");
  208.             printf("\nError message: %d\n ",error); 
  209.             switch(error){
  210.                 case '4':
  211.                     printf("Failure to open portrait font file\n");
  212.                     break;
  213.                 case '5':
  214.                     printf("Landscape file exists; rename.\n");
  215.                     break;
  216.                 case '6':
  217.                     printf("Not font file?? First char should be 'escape'\n");
  218.                     break;
  219.                 default:
  220.                     break;}
  221.             exit(0); 
  222.             }
  223.         printf("\nFont converted: %s --> %s\n",argv[1],argv[2]);
  224.         exit(0);
  225.     }
  226.     else {
  227.         printf("\nArgument ERROR. Correct form is:");
  228.         printf("\n'path'PORTOLAN  PORTRAIT LANDSCAPE\n\n");
  229.         exit(0);
  230.     }
  231. }
  232.  
  233. if(error = init_window() != 0) {
  234.     clear_window();
  235.     exit(FALSE);                 /* Open the window    */
  236.     }
  237. for ( quit_flag = FALSE; ! quit_flag ; ) {
  238.  
  239.     while (! (message=(struct IntuiMessage *)GetMsg(p_Window->UserPort)) )
  240.     WaitPort( p_Window->UserPort );  /* Wait for input event          */
  241.  
  242.     class = message->Class;    code = message->Code;   /* Get event info */
  243.     ReplyMsg( message );    /* Tell intuition we're through with event   */
  244.  
  245.     switch ( class ) {           /*    Process the input event           */
  246.     case CLOSEWINDOW:   quit_flag = TRUE;
  247.         break;
  248.  
  249.     /* Heres what you're looking for...    */
  250.     case MENUPICK:
  251.        if ( (MENUNUM( code ) == 0) && (ITEMNUM( code ) == 0) ) {
  252.         /* Call up the filename requester for portrait font */
  253.  
  254.         if ( get_fname(p_Window, "Portrait Path/File",file_name,dir_name) ) {
  255.             temp = strrchr(dir_name,SLASH);
  256.             if (strlen(temp) != ONE) 
  257.                 strcat(dir_name, slash);  /* add '/' if missing */
  258.             strcpy(portrait,dir_name);    /* form path name */
  259.             strcat(portrait,file_name); /* complete portrait path */
  260.             strcat(file_name,LAND);  /* add default extension */ 
  261.         }
  262.         else {
  263.             printf("User aborted request\n");
  264.             delay();
  265.             clear_window();
  266.             exit(0); }
  267.             
  268.         /* Call up the filename requester for landscape font */
  269.  
  270.         if ( get_fname(p_Window, "Rename for LANDscape:",file_name,dir_name) )  {
  271.             temp = strrchr(dir_name,SLASH);
  272.             if (strlen(temp) != ONE) 
  273.                 strcat(dir_name, slash);  /* add '/' if missing */
  274.             strcpy(landscape,dir_name);    /* form path name */
  275.             strcat(landscape,file_name);
  276.         }  
  277.         else {   
  278.             printf("User aborted file requester\n");
  279.             delay();
  280.             clear_window();
  281.             exit(0); }
  282.  
  283.         if (error = convert(portrait,landscape) != 0) { /*  process the request */
  284.             printf("Failure to process font\n");
  285.             printf("\nError message: %d\n ",error); 
  286.             switch(error){
  287.                 case '4':
  288.                     printf("Failure to open portrait font file\n");
  289.                     break;
  290.                 case '5':
  291.                     printf("Landscape file exists; rename.\n");
  292.                     break;
  293.                 case '6':
  294.                     printf("Not font file?? First char should be 'escape'\n");
  295.                     break;
  296.                 default:
  297.                     break;}
  298.             delay();
  299.             clear_window();
  300.             exit(0); 
  301.             }
  302.  
  303.         strcpy(file_name,"");
  304.         break;
  305.  
  306.     } /* if MENUM */
  307.     
  308.     } /* SWITCH */ 
  309.     
  310.         
  311.    } /* for loop looking for quit.flag */
  312.    
  313. delay();   
  314. clear_window();               /* Return all resources and exit */
  315.  
  316. }
  317.